#pragma once

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include "Log.hpp"

#define Die(code)   \
    do              \
    {               \
        exit(code); \
    } while (0)
#define CONV(v) (struct sockaddr *)v // 类型强转
enum class Code
{
    SOCKETERROR = 1,
    BINDERROR,
    USAGEERROR
};
// key和value输出型参数
bool SplitString(std::string &line, std::string *key, std::string *value, const std::string &sep)
{
    auto pos = line.find(sep);
    if (pos == std::string::npos)
        return false;
    *key = line.substr(0, pos);
    *value = line.substr(pos + sep.size());
    if (key->empty() || value->empty())
        return false;
    return true;
}